<template>
  <Modal v-model="modal.show" title="加减分" @on-ok="downloadReport" @on-cancel="closeModal">
    <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="100">
      <FormItem label="审核状态" prop="status">
        <Select filterable
          v-model="statusModel"
          placeholder="审核状态"
          clearable
          style="width:120px;margin-left: 8px"
          @on-change="selectStatus"
        >
          <Option value="1">未审核</Option>
          <Option value="2">已通过</Option>
          <Option value="3">已驳回</Option>
        </Select>
      </FormItem>
      <FormItem label="时间" prop="Dates">
        <DatePicker
          :editable="false"
          type="datetimerange"
          :value="formValidate.Dates"
          format="yyyy-MM-dd HH:mm"
          placement="bottom-start"
          confirm
          ref="datePicker"
          placeholder="选择日期"
          style="width: 280px"
          transfer
          :options="disabledOptions"
          @on-ok="clickOkBtn"
          @on-clear="clickClearBtn"
          @on-open-change="switchOpenChange"
          @on-change="changeDates"
        ></DatePicker>
        <p style="color:#ff9900;font-size:10px;line-height: 2;">
          <Icon type="ios-information-circle-outline" />
          选择同一天的时间段，请先双击要选择的日期
        </p>
        <p style="color:#ff9900;font-size:10px;line-height: 2;">
          <Icon type="ios-information-circle-outline" />
          开始时间不能小于开始时间
        </p>
      </FormItem>
    </Form>
    <!-- <div slot="footer" class="footer">
      <Button type="text" size="large" @click="showScoreModal = false">取消</Button>
      <Button type="primary" size="large" @click="downloadReport" :loading="modal.loading"
        >确定</Button
      >
    </div> -->
  </Modal>
</template>
<script>
import recoverTime from '@/mixin/recoverTime';
export default {
  name: 'DownloadReport',
  components:{},
  mixins: [recoverTime],
  data() {
    // 验证时间选择是否正确
    const validateDate = (rule, value, callback) => {
      if (value) {
        let startTime = this.formValidate.Dates[0];
        let endTime = this.formValidate.Dates[1];
        if (!startTime || !endTime) {
          callback(new Error('请选择时间'));
        } else if (new Date(startTime).getTime() < new Date().getTime()) {
          callback(new Error('开始时间必须大于当前时间'));
        } else {
          callback();
        }
      } else {
        callback();
      }
    };
    return {
      modal: {
        show: false,
        title: '下载统计信息',
        loading: true
      },
      disabledOptions: {
        disabledDate(date) {
          return date && date.valueOf() < Date.now() - 86400000;
        }
      },
      formValidate: {
        checkStatus: '',
        dates: []
      },
      ruleValidate: {
        checkStatus: [{ required: true, message: '请选择攻击类型', trigger: 'change' }],
        dates: [
          { required: true, type: 'array', message: '不能为空', trigger: 'change, blur' },
          { validator: validateDate, trigger: 'change, blur' }
        ]
      }
    };
  },
  created() {
    this._formValidate = { ...this.formValidate };
  },
  methods: {
    openModal(sceneInfo) {
      this.sceneInfo = sceneInfo;
      this.modal.show = true;
      this.formValidate = { ...this.formValidate };
    },
    closeModal() {
      this.modal.show = false;
      this.$refs.formValidate.resetFields();
    },
    downloadReport() {
      let sceneId = this.sceneInfo.id;
      let sceneName = this.sceneInfo.name;
      let href = `/api/compete/scoring/exportReport/${sceneId}/${sceneName}`;
      let a = document.createElement('a');
      document.body.appendChild(a);
      a.href = href;
      a.download = ''; //命名下载名称
      a.click(); //点击触发下载
      a.remove();
      this.cancelLoading();
    },
    cancelLoading() {
      this.modal.loading = false;
      setTimeout(() => {
        this.modal.loading = true;
      });
    }
  }
};
</script>
<style scoped></style>
